<?php	
	$db = new MySQL();   
	$table = "catalog";
	$id = $_GET['id'];	
	$mod = $_GET['mod'];
	
	$linkto = (isset($_POST["linkto"]))?$_POST["linkto"]:"";
		$linkto = str_replace("'", "\\'", $linkto);
		$linkto = str_replace("\\\'", "\\'", $linkto);
	
	$typeshow = (isset($_POST["typeshow"]))?$_POST["typeshow"]:"";
	
	if ($_POST["form_"]=="edit")
	{
		if(isset($_GET['id']))
		{
			$query_image = "select * from $table where id='$id'";
			$sql_image = $db->select($query_image);
			$tt_image = $db->fetch($sql_image);				
			$filename  = $tt_image['filename'];	
		}
		
		//filename
		if ($_FILES['filename']['name'] != "")	
		{				
						
			$parts1=pathinfo($_FILES['filename']['name']);
			$ext1=".".strtolower($parts1["extension"]);																			

			
			if (file_exists("../catalog/".$_FILES["filename"]["name"]))
			{
				$attach_file = date("sihdmy").$ext1;
			}
			else 
			{											  
				$attach_file = str_replace(" ","_",$_FILES["filename"]["name"]);
			}
			
			if(move_uploaded_file($_FILES["filename"]["tmp_name"], "../catalog/".$attach_file))
			{	
				$filemod = "../catalog/".$attach_file;
				
				chmod($filemod,0777);
				
				resize_jpg($filemod,$filemod,330,0);
				
				
				if($filename !="" && file_exists("../catalog/".$filename))   
				{
					unlink("../catalog/".$filename); 					
				}	
				$filename = $attach_file;
			}					
		}				
		//cap nhat du lieu
		$query="update $table set filename = '$filename', linkto = '$linkto',  typeshow = '$typeshow' ";
		$query.=" where id='$id'";
                
		$sql = $db->update($query);								
		
                $db->close();							
                echo "<script>location='?mod=".$mod."&act=edit&id=".$id."'</script>";	
	}	
		

?>
